Imports System
Imports System.Collections.Generic
Imports System.Reflection
Imports System.Text

Public Class Reflector
    Private Const CommonFlags As BindingFlags = BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.IgnoreCase

    Public Shared Function CreateInstance(ByVal type As Type, ByVal args() As Object) As Object
        Return Reflector.InvokeMember(type, Nothing, Nothing, Reflector.CommonFlags Or BindingFlags.CreateInstance Or BindingFlags.Instance, args)

    End Function

    Public Shared Sub SetProperty(ByVal Target As Object, ByVal PropertyName As String, ByVal value As Object)
        Reflector.InvokeMember(Target.GetType, Target, PropertyName, Reflector.CommonFlags Or BindingFlags.SetProperty Or BindingFlags.Instance, value)
    End Sub

    Public Shared Function GetProperty(ByVal Target As Object, ByVal PropertyName As String) As Object
        Return Reflector.InvokeMember(Target.GetType, Target, PropertyName, Reflector.CommonFlags Or BindingFlags.GetProperty Or BindingFlags.Instance, Nothing)
    End Function

    Public Shared Function GetField(ByVal Target As Object, ByVal FieldName As String) As Object
        Return Reflector.InvokeMember(Target.GetType, Target, FieldName, Reflector.CommonFlags Or BindingFlags.GetField Or BindingFlags.Instance, Nothing)
    End Function

    Public Shared Sub SetField(ByVal Target As Object, ByVal FieldName As String, ByVal value As Object)
        Reflector.InvokeMember(Target.GetType, Target, FieldName, Reflector.CommonFlags Or BindingFlags.SetField Or BindingFlags.Instance, value)
    End Sub

    Public Shared Sub SetField1(ByVal Target As Object, ByVal FieldName As String, ByVal value As Object)
        Reflector.InvokeMember1(Target.GetType, Target, FieldName, Reflector.CommonFlags Or BindingFlags.SetField Or BindingFlags.Instance, value)
    End Sub


    Private Shared Function InvokeMember(ByVal Type As Type, ByVal Target As Object, ByVal MemberName As String, ByVal Flags As BindingFlags, ByVal args() As Object) As Object
        Return Type.InvokeMember(MemberName, Flags, Nothing, Target, args)
    End Function

    Private Shared Function InvokeMember1(ByVal Type As Type, ByVal Target As Object, ByVal MemberName As String, ByVal Flags As BindingFlags, ByVal args As Object) As Object
        Return Type.InvokeMember(MemberName, Flags, Nothing, Target, args)
    End Function

End Class
